<?php
/**
 * Minhlog Minh_Resource 视图资源类
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   Minh
 * @package    Minh_Resource
 * @copyright  Copyright (c) 2009-2010 Minh.Shu Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: View.php 9 2010-01-19 12:47:13Z Minh.Shu $
 *
 */

class Minh_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    protected $_view;

    public function init ()
    {
        return $this->getView();
    }

    /**
     * 获取视图资源对象
     * @return $view
     */
    public function getView ()
    {
        if (null === $this->_view) {
            //关闭模板自动分发
            Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');

            $options = $this->getOptions();
            $view = new Zend_View($options);
            if (! empty($options['params'])) {
                foreach ($options['params'] as $key => $value) {
                    $view->$key = $value;
                }
            }
            $view->zfversion = Zend_Version::VERSION;

            $view->doctype('XHTML1_STRICT');
            $view->headTitle($view->siteName)->setSeparator(' - ')->append($view->siteTitle);
            $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=' . $view->encoding)
                    ->appendHttpEquiv('X-UA-Compatible', 'IE=8')
                    ->appendName('author','Minh.Shu')
                    ->appendName('copyright','copyright by Minhlog')
                    ->appendName('generator','Minhlog ' . $view->version)
            ;
            $view->headLink()
                    ->appendAlternate('http://feed.minhlog.com','application/rss+xml','RSS 2.0')
                    ->headLink(array('rel' => 'bookmark',
                    'href' => '/public/image/minhlog.ico'
                    )
                    )
                    ->headLink(array('rel' => 'shortcut icon',
                    'href' => '/public/image/minhlog.ico'
                    )
                    )
            ;
            $view->headScript()->prependFile('/public/js/jquery-1.4.min.js');
            Zend_Registry::set('view', $view);
            $this->_view = $view;
        }
        return $this->_view;
    }
}